package com.cyt.wx.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.model.vo.SelectVo;
import com.cyt.base.util.*;
import com.cyt.sys.model.po.SysFile;
import com.cyt.sys.model.po.SysUser;
import com.cyt.sys.model.vo.SysFileVo;
import com.cyt.sys.service.SysFileService;
import com.cyt.sys.service.impl.BaseServiceImpl;
import com.cyt.sys.util.FilePathUtil;
import com.cyt.sys.util.GlobalExcelDictHandler;
import com.cyt.wx.dao.WxEducationUserDao;
import com.cyt.wx.model.po.WxEducationUser;
import com.cyt.wx.model.po.WxMember;
import com.cyt.wx.model.vo.WxEducationUserImportVo;
import com.cyt.wx.model.vo.WxEducationUserVerifyImportVo;
import com.cyt.wx.model.vo.WxEducationUserVo;
import com.cyt.wx.service.WxEducationUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.*;

/**
 * 学校通用用户模块-基础用户Service层实现类
 *
 * @author han jun
 * @date 2019-8-29 13:41:23
 */
@Service("wxEducationUserService")
public class WxEducationUserServiceImpl extends BaseServiceImpl<WxEducationUser> implements WxEducationUserService {

    @Resource
    private SysFileService sysFileService;
    @Resource
    private WxEducationUserDao wxEducationUserDao;

    @Autowired
    public void setBaseDao(WxEducationUserDao wxEducationUserDao) {
        this.baseDao = wxEducationUserDao;
    }

    /**
     * 查询对象集合
     *
     * @param wxEducationUserVo 对象
     * @return List 对象集合
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    public List<WxEducationUser> listExample(WxEducationUserVo wxEducationUserVo) {
        Example example = new Example(WxEducationUser.class);
        example.setOrderByClause(" create_time desc");
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(wxEducationUserVo.getUserNumber())) {
            criteria.andEqualTo("userNumber", wxEducationUserVo.getUserNumber());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getApplyId())) {
            criteria.andEqualTo("applyId", wxEducationUserVo.getApplyId());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getMemberId())) {
            criteria.andEqualTo("memberId", wxEducationUserVo.getMemberId());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getLoginName())) {
            criteria.andEqualTo("loginName", wxEducationUserVo.getLoginName());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getName())) {
            criteria.andLike("name", "%" + wxEducationUserVo.getName() + "%");
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getMobile())) {
            criteria.andLike("mobile", "%" + wxEducationUserVo.getMobile() + "%");
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getUserType())) {
            criteria.andEqualTo("userType", wxEducationUserVo.getUserType());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getCreateUser())) {
            criteria.andEqualTo("createUser", wxEducationUserVo.getCreateUser());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getId())) {
            criteria.andEqualTo("id", wxEducationUserVo.getId());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getStatus())) {
            criteria.andEqualTo("status", wxEducationUserVo.getStatus());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getExamine())) {
            criteria.andEqualTo("examine", wxEducationUserVo.getExamine());
        }
        if (StringUtils.isNotEmpty(wxEducationUserVo.getApplyId())) {
            criteria.andEqualTo("applyId", wxEducationUserVo.getApplyId());
        }
        criteria.andEqualTo("removeTag", DictCode.BASE_REMOVE_TAG_NORMAL);
        return wxEducationUserDao.selectByExample(example);
    }

    /**
     * 分页查询
     *
     * @param wxEducationUserVo 接受参数对象
     * @param pageNum          分页数
     * @param pageSize         每页显示条数
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    public ReturnResult page(WxEducationUserVo wxEducationUserVo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy(" create_time desc");
        List<WxEducationUser> list = listExample(wxEducationUserVo);
        PageInfo<WxEducationUser> page = new PageInfo<>(list);
        return new ReturnResult(page.getList(), page.getTotal(), page.isHasNextPage());
    }

    /**
     * 学生照片审核的分页界面
     *
     * @param wxEducationUserVo 接受参数对象
     * @param pageNum          分页数
     * @param pageSize         每页显示条数
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    public  ReturnResult pageNewImageStudent(WxEducationUserVo wxEducationUserVo, int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy(" create_time desc");
        List<WxEducationUser> newList = new ArrayList<>();
        List<WxEducationUser> list = listExample(wxEducationUserVo);
        for (WxEducationUser wxEducationUser:list){
            if (!StringUtils.isEmpty(wxEducationUser.getExamine())){
                //图片操作
                SysFileVo sysFileVo = new SysFileVo();
                sysFileVo.setObjectId(wxEducationUser.getObjectidOne());

                String str ="";
                if (StringUtils.isEmpty(wxEducationUser.getObjectidOne())){
                }else {
                   List<SysFile> Imagelist = (List<SysFile>) sysFileService.list(sysFileVo).getData();
                   if (Imagelist.size()>0){
                       wxEducationUser.setIssnumImageUrl("/sysFile/showFileByPath?path="+Imagelist.get(0).getPath());
                   }
                }
                String strnew= DateUtil.getDateText(wxEducationUser.getUpdateTime(),"yyyy:MM:dd HH:mm");
                wxEducationUser.setUserNumber(strnew);
                newList.add(wxEducationUser);
            }
        }
        PageInfo<WxEducationUser> page = new PageInfo<>(newList);
        return new ReturnResult(page.getList(), page.getTotal(), page.isHasNextPage());
    }


    /**
     * 添加或更新
     *
     * @param wxEducationUserVo 参数接受对象
     * @param sysUser      当前用户
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReturnResult addOrUpdate(WxEducationUserVo wxEducationUserVo, SysUser sysUser) {
        if (StringUtils.isBlank(wxEducationUserVo.getId())) {
            WxEducationUser wxEducationUser = new WxEducationUser(sysUser);
            wxEducationUser.setApplyId(wxEducationUserVo.getApplyId());
            wxEducationUser.setMemberId(wxEducationUserVo.getMemberId());
            wxEducationUser.setLoginName(wxEducationUserVo.getLoginName());
            wxEducationUser.setUserNumber(wxEducationUserVo.getUserNumber());
            wxEducationUser.setUserType(wxEducationUserVo.getUserType());
            wxEducationUser.setName(wxEducationUserVo.getName());
            wxEducationUser.setStatus(wxEducationUserVo.getStatus());
            wxEducationUser.setMobile(wxEducationUserVo.getMobile());
            wxEducationUser.setExamine(wxEducationUserVo.getExamine());
            wxEducationUser.setObjectidOne(wxEducationUserVo.getObjectidOne());
            if (StringUtils.isNotEmpty(wxEducationUserVo.getMobile()) && wxEducationUserVo.getMobile().length() == 11) {
                wxEducationUser.setPassword(MD5Util.MD5Encode(StrUtil.sub(wxEducationUserVo.getMobile(), 5, 11)));
            } else {
                wxEducationUser.setPassword(MD5Util.MD5Encode(BaseConstant.DEFAULT_EDUCATION_USER_PASSWORD));
            }
            wxEducationUserDao.insert(wxEducationUser);
            return new ReturnResult(BaseConstant.DATABASE_SUCCEED_INSERT);
        } else {
            WxEducationUser wxEducationUser = wxEducationUserDao.selectByPrimaryKey(wxEducationUserVo.getId());
            wxEducationUser.setLoginName(wxEducationUserVo.getLoginName());
            wxEducationUser.setUserNumber(wxEducationUserVo.getUserNumber());
            wxEducationUser.setUserType(wxEducationUserVo.getUserType());
            wxEducationUser.setMobile(wxEducationUserVo.getMobile());
            wxEducationUser.setName(wxEducationUserVo.getName());
            wxEducationUser.setStatus(wxEducationUserVo.getStatus());
            wxEducationUser.setExamine(wxEducationUserVo.getExamine());
            wxEducationUser.setObjectidOne(wxEducationUserVo.getObjectidOne());
            wxEducationUser.setUpdateTime(new Date());
            wxEducationUser.setUpdateUser(sysUser.getId());
            wxEducationUserDao.updateByPrimaryKey(wxEducationUser);
            return new ReturnResult(BaseConstant.DATABASE_SUCCEED_UPDATE);
        }
    }


    /**
     * 更新一寸照片接口
     *
     * @param wxEducationUserVo 参数接受对象
     * @param sysUser      当前用户
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReturnResult updateOneImage(WxEducationUserVo wxEducationUserVo, SysUser sysUser){
        WxEducationUser wxEducationUser = wxEducationUserDao.selectByPrimaryKey(wxEducationUserVo.getId());
        if (StringUtils.isNotBlank(wxEducationUserVo.getObjectidOne())){
            wxEducationUser.setObjectidOne(wxEducationUserVo.getObjectidOne());
        }
        wxEducationUser.setExamine(wxEducationUserVo.getExamine());
        wxEducationUser.setUpdateUser(sysUser.getId());
        wxEducationUser.setUpdateTime(new Date());
        wxEducationUserDao.updateByPrimaryKey(wxEducationUser);
        return new ReturnResult(ErrorCode.CODE_0, BaseConstant.DATABASE_SUCCEED_UPDATE);

    }

    /**
     * 多个图片审核
     *
     * @param wxEducationUserVo 参数接受对象
     * @param sysUser      当前用户
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReturnResult updateMoreImage(WxEducationUserVo wxEducationUserVo, SysUser sysUser,String ids){
        String[] idItem = ids.split(",");
        for (String string:idItem){
            WxEducationUser wxEducationUser = wxEducationUserDao.selectByPrimaryKey(string);
            if (StringUtils.isNotBlank(wxEducationUserVo.getObjectidOne())){
                wxEducationUser.setObjectidOne(wxEducationUserVo.getObjectidOne());
            }
            wxEducationUser.setExamine(wxEducationUserVo.getExamine());
            wxEducationUser.setUpdateUser(sysUser.getId());
            wxEducationUser.setUpdateTime(new Date());
            wxEducationUserDao.updateByPrimaryKey(wxEducationUser);
        }

        return new ReturnResult(ErrorCode.CODE_0, BaseConstant.DATABASE_SUCCEED_UPDATE);

    }



    /**
     * 根据条件逻辑删除
     *
     * @param wxEducationUserVo 参数接受对象
     * @param sysUser 当前用户
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReturnResult remove(WxEducationUserVo wxEducationUserVo, SysUser sysUser) {
        //要修改的字段
        WxEducationUser wxEducationUser = new WxEducationUser();
        wxEducationUser.setRemoveTag(DictCode.BASE_REMOVE_TAG_DELETE);
        wxEducationUser.setUpdateUser(sysUser.getId());
        wxEducationUser.setUpdateTime(new Date());
        //筛选条件
        Example example = new Example(WxEducationUser.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(wxEducationUserVo.getId())) {
            criteria.andIn("id", Arrays.asList(wxEducationUserVo.getId().split(",")));
        }
        criteria.andEqualTo("removeTag", DictCode.BASE_REMOVE_TAG_NORMAL);
        wxEducationUserDao.updateByExampleSelective(wxEducationUser, example);
        return new ReturnResult(ErrorCode.CODE_0, BaseConstant.DATABASE_SUCCEED_DEL);
    }

    @Override
    public ReturnResult resetPassword(WxEducationUserVo wxEducationUserVo, SysUser sysUser) {
        //要修改的字段
        List<String> idList = Arrays.asList(wxEducationUserVo.getId().split(","));
        if (idList != null && idList.size() > 0) {
            for (String id : idList) {
                WxEducationUser wxEducationUser = this.selectByPrimaryKey(id);
                String mobile = wxEducationUser.getMobile();
                if (StringUtils.isNotEmpty(mobile) && mobile.length() == 11) {
                    wxEducationUser.setPassword(MD5Util.MD5Encode(StrUtil.sub(mobile, 5, 11)));
                } else {
                    wxEducationUser.setPassword(MD5Util.MD5Encode(BaseConstant.DEFAULT_EDUCATION_USER_PASSWORD));
                }
                wxEducationUser.setUpdateUser(sysUser.getId());
                wxEducationUser.setUpdateTime(new Date());
                wxEducationUserDao.updateByPrimaryKey(wxEducationUser);
            }
        }
        return new ReturnResult("已设置为手机号后6位");
    }

    /**
     * 根据条件物理删除
     *
     * @param wxEducationUserVo 参数接受对象
     * @param sysUser      当前用户
     * @return ReturnResult
     * @author han jun
     * @date 2019-8-29 13:41:23
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReturnResult delete(WxEducationUserVo wxEducationUserVo, SysUser sysUser) {
        //筛选条件
        Example example = new Example(WxEducationUser.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(wxEducationUserVo.getId())) {
            criteria.andIn("id", Arrays.asList(wxEducationUserVo.getId().split(",")));
        }
        wxEducationUserDao.deleteByExample(example);
        return new ReturnResult(ErrorCode.CODE_0, BaseConstant.DATABASE_SUCCEED_DEL);
    }

    @Override
    public Integer selectTeacherCount() {
        Example example = new Example(WxEducationUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("userType", BaseConstant.EDUCATION_USER_TYPE_ADMIN);
        criteria.orEqualTo("userType", BaseConstant.EDUCATION_USER_TYPE_TEACHER);
        return wxEducationUserDao.selectCountByExample(example);
    }

    @Override
    public Integer selectStudentCount() {
        Example example = new Example(WxEducationUser.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userType", BaseConstant.EDUCATION_USER_TYPE_STUDENT);
        return wxEducationUserDao.selectCountByExample(example);
    }

    @Override
    public void insertList(List<WxEducationUser> list) {
        wxEducationUserDao.insertList(list);
    }

    @Override
    public boolean checkByMemberId(String memberId) {
        WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
        wxEducationUserVo.setMemberId(memberId);
        List<WxEducationUser> wxEducationUserList = this.listExample(wxEducationUserVo);
        if (CollUtil.isNotEmpty(wxEducationUserList)) {
            return true;
        }
        return false;
    }

    @Override
    public WxEducationUser selectEducationUserByMemberId(String memberId) {
        WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
        wxEducationUserVo.setMemberId(memberId);
        List<WxEducationUser> wxEducationUserList = this.listExample(wxEducationUserVo);
        if (CollUtil.isNotEmpty(wxEducationUserList)) {
            return wxEducationUserList.get(0);
        }
        return null;
    }

    @Override
    public ReturnResult importData(HttpServletRequest request, MultipartFile file, String catalog, String update, String applyId, SysUser sysUser) {
        // 1、不更新已存在数据，2、更新存在数据
        ReturnResult returnResult = sysFileService.fileUpload(file, request, catalog, BaseConstant.FILE_TYPE_EXECL);
        if (ErrorCode.CODE_0 == returnResult.getCode()) {
            String filePath = FilePathUtil.acceptCheckRealPath(request) + returnResult.getData().toString();
            ImportParams params = new ImportParams();
            params.setTitleRows(0);
            params.setHeadRows(1);
            params.setNeedVerify(true);
            // 解决多读取问题，如果出现没有导入问题，需要将该属性去除
            params.setKeyIndex(0);
            // 如果有code码需要设置，现有bug，需要修改源码CellValueService
            params.setDictHandler(new GlobalExcelDictHandler());
            ExcelImportResult<WxEducationUserVerifyImportVo> result = ExcelImportUtil.importExcelMore(new File(filePath), WxEducationUserVerifyImportVo.class, params);
            List<WxEducationUserVerifyImportVo> educationUserImportList = result.getList();
            if (CollUtil.isNotEmpty(educationUserImportList)) {
                Map<String, WxEducationUserImportVo> educationUserMap = new HashMap<>();
                String key;
                for (WxEducationUserImportVo educationUser : educationUserImportList) {
                    key = educationUser.getUserNumber();
                    if (educationUserMap.keySet().contains(key)) {
                        continue;
                    }
                    educationUserMap.put(key, educationUser);
                }
                List<WxEducationUser> wxEducationUserList = new ArrayList<>();
                for (Map.Entry<String, WxEducationUserImportVo> entry : educationUserMap.entrySet()) {
                    // 账号不存在，保存进用户表
                    WxEducationUserImportVo userFrom = entry.getValue();
                    // 查询账号是否存在
                    WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
                    wxEducationUserVo.setUserNumber(userFrom.getUserNumber());
                    List<WxEducationUser> list = this.listExample(wxEducationUserVo);
                    WxEducationUser wxEducationUser;
                    if (CollUtil.isNotEmpty(list)) {
                        wxEducationUser = new WxEducationUser();
                        String mobile = userFrom.getMobile();
                        wxEducationUser.setId(BaseUtil.uId());
                        wxEducationUser.setApplyId(applyId);
                        wxEducationUser.setLoginName(userFrom.getUserNumber());
                        wxEducationUser.setMobile(mobile);
                        wxEducationUser.setName(userFrom.getName());
                        wxEducationUser.setUserNumber(userFrom.getUserNumber());
                        wxEducationUser.setStatus(BaseConstant.BASE_STATUS_YES);
                        if (StringUtils.isNotEmpty(mobile) && mobile.length() == 11) {
                            wxEducationUser.setPassword(MD5Util.MD5Encode(StrUtil.sub(mobile, 5, 11)));
                        } else {
                            wxEducationUser.setPassword(MD5Util.MD5Encode(BaseConstant.DEFAULT_EDUCATION_USER_PASSWORD));
                        }
                        wxEducationUser.setUserType(userFrom.getUserType());
                        wxEducationUser.setRemoveTag(BaseConstant.REMOVE_TAG_NO);
                        wxEducationUser.setCreateUser(sysUser.getId());
                        wxEducationUser.setUpdateUser(sysUser.getId());
                        wxEducationUser.setCreateTime(cn.hutool.core.date.DateUtil.date());
                        wxEducationUser.setUpdateTime(cn.hutool.core.date.DateUtil.date());
                        wxEducationUserList.add(wxEducationUser);
                    } else {
                        if (StringUtils.equals(update, BaseConstant.IMPORT_STATUS_UPDATE_NO)) {
                            continue;
                        }
                        // 直接更新
                        wxEducationUser = list.get(0);
                        boolean flag = checkUserNumberUnique(wxEducationUser.getId(), userFrom.getUserNumber(), sysUser.getId());
                        // false表示可以使用
                        if (!flag) {
                            wxEducationUser.setLoginName(userFrom.getUserNumber());
                            wxEducationUser.setMobile(userFrom.getMobile());
                            wxEducationUser.setName(userFrom.getName());
                            wxEducationUser.setUserNumber(userFrom.getUserNumber());
                            wxEducationUser.setUserType(userFrom.getUserType());
                            wxEducationUser.setUpdateUser(sysUser.getId());
                            wxEducationUser.setUpdateTime(new Date());
                            this.updateByPrimaryKey(wxEducationUser);
                        }
                    }
                }
                // 保存
                if (wxEducationUserList != null && wxEducationUserList.size() > 0) {
                    this.insertList(wxEducationUserList);
                }
            }
            // 行号从0开始，要加上titleRows和headRows
            if (result.isVerfiyFail()) {
                // 如果错误，打印出提醒，直接返回
                int successNum = 0;
                int failNum = result.getFailList().size();
                if (result.getList() != null && result.getList().size() > 0) {
                    successNum = result.getList().size();
                }
                String errorMsg = String.format("共导入%s条，成功%s条，失败%s条。", successNum + failNum, successNum, failNum);
                List<WxEducationUserVerifyImportVo> failList = result.getFailList();
                return new ReturnResult(ErrorCode.CODE_1, failList, errorMsg);
            }
        }
        return returnResult;
    }

    @Override
    public boolean checkUserNumberUnique(String id, String userNumber, String createUser) {
        String recordNumber = "";
        if (StringUtils.isNotEmpty(id)) {
            WxEducationUser wxEducationUser = this.selectByPrimaryKey(id);
            recordNumber = wxEducationUser.getUserNumber();
        }
        WxEducationUser wxEducationUserSearch = new WxEducationUser();
        wxEducationUserSearch.setUserNumber(userNumber);
        wxEducationUserSearch.setCreateUser(createUser);
        WxEducationUser wxEducationUser = this.selectOne(wxEducationUserSearch);
        if (wxEducationUser != null) {
            if (StringUtils.isNotEmpty(recordNumber) && StringUtils.equals(userNumber, recordNumber)) {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }

    @Override
    public ReturnResult login(WxMember wxMember, String loginName, String password) {
        // 本账号已绑定过，请用正确的账号登录
        WxEducationUserVo wxEducationUserSearch = new WxEducationUserVo();
        wxEducationUserSearch.setMemberId(wxMember.getId());
        List<WxEducationUser> wxEducationMemberList = this.listExample(wxEducationUserSearch);
        if (CollUtil.isNotEmpty(wxEducationMemberList)) {
            // 如果本身绑定，则直接返回成功
            WxEducationUser wxEducationUser = wxEducationMemberList.get(0);
            if (StringUtils.equals(wxEducationUser.getLoginName(), loginName)) {
                return new ReturnResult(wxEducationUser);
            }
            return new ReturnResult(ErrorCode.CODE_1, "本账号已绑定过，请用正确的账号登录");
        }
        // 查看用户是否存在
        WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
        wxEducationUserVo.setLoginName(loginName);
        wxEducationUserVo.setCreateUser(wxMember.getCreateUser());
        List<WxEducationUser> wxEducationUserList = this.listExample(wxEducationUserVo);
        if (wxEducationUserList == null || wxEducationUserList.size() == 0) {
            return new ReturnResult(ErrorCode.CODE_1, "未查询到该账号，请联系管理员导入");
        }
        WxEducationUser wxEducationUser = wxEducationUserList.get(0);
        // 不是本账号
        if (StringUtils.isNotEmpty(wxEducationUser.getMemberId()) && !StringUtils.equals(wxEducationUser.getMemberId(), wxMember.getId())) {
            return new ReturnResult(ErrorCode.CODE_1, "该账号已被其他人绑定");
        }
        if (!StringUtils.equals(wxEducationUser.getPassword(), MD5Util.MD5Encode(password))) {
            return new ReturnResult(ErrorCode.CODE_1, "密码不正确");
        }
        wxEducationUser.setMemberId(wxMember.getId());
        this.updateByPrimaryKey(wxEducationUser);
        return new ReturnResult(wxEducationUser);
    }


    /**
     * 获取教师人员选择器
     *
     * @param wxEducationUserVo 筛选条件
     * @return ReturnResult
     * @author Jun Han
     * @date 2019/9/26 15:59
     */
    @Override
    public ReturnResult selector(WxEducationUserVo wxEducationUserVo){
        List<WxEducationUser> list = this.listExample(wxEducationUserVo);
        List<SelectVo> selectVoList=new ArrayList<>();
        if(list!=null&&list.size()>0){
            for(WxEducationUser wxEducationUser :list){
                List<String> showNameList=new ArrayList<>();
                showNameList.add(wxEducationUser.getName());
                showNameList.add(wxEducationUser.getUserNumber());
                selectVoList.add(new SelectVo(wxEducationUser.getId(), wxEducationUser.getName(),showNameList));
            }
        }
        return new ReturnResult(selectVoList);
    }


    /**
     * 获取id 对应的学号
     *
     * @param ids
     * @return ReturnResult
     * @author Jun Han
     * @date 2019/9/26 17:22
     */
    @Override
    public ReturnResult getAllteacherNumber(String ids){
        String[] strList = ids.split(",");
        List<String> list = new ArrayList<>();
        for (String str:strList){
            WxEducationUser wxEducationUser = this.selectByPrimaryKey(str);
          if (!StringUtils.isBlank(wxEducationUser.getUserNumber())){
              list.add(wxEducationUser.getUserNumber());
          }
        }
        String join = String.join(",", list);
        return new ReturnResult(join);
    }

    /**
     * 获取工号 对应的id
     *
     * @param userNumbers
     * @return ReturnResult
     * @author Jun Han
     * @date 2019/9/26 17:22
     */
    @Override
    public ReturnResult getAllIdsByUserNumber(String userNumbers,String createUser){
        String[] strList = userNumbers.split(",");
        List<String> list = new ArrayList<>();
        for (String str:strList){
            WxEducationUserVo wxEducationUserVo = new WxEducationUserVo();
            wxEducationUserVo.setUserNumber(str);
            //wxEducationUserVo.setCreateUser(createUser);
            List<WxEducationUser> users = this.listExample(wxEducationUserVo);
            if (users != null && users.size() > 0) {
                WxEducationUser wxEducationUser = users.get(0);
                list.add(wxEducationUser.getId());
            }

        }
        String join = String.join(",", list);
        return new ReturnResult(join);
    }
}